<?php
	foreach ($fields as $v) {
		if($v['Field']!='id'){
			$field[]=$v['Field'];
		}
	}
;?>
class <?=$dbname;?>m extends MY_Model{
	protected $dbname="<?=$dbname;?>";
	protected $insertFields=array('<?=implode("','", $field);?>');
	protected $updateFields=array('<?=implode("','", $field);?>');
	/*取出数据*/
	public function search($pSize=2){
		/*标题搜索*/
		<?php foreach($fields as $v):
		if($v['Field']=='id'){
			continue;
		}
		?>
#按照<?=$v['Field'];?>搜索
		$<?=$v['Field'];?>=$this->input->get('<?=$v['Field'];?>');
		if($<?=$v['Field'];?>){
			$this->db->where('<?=$v['Field'];?>',$<?=$v['Field'];?>);
		}
		<?php endforeach;?>
/*设置将要操作的表*/
		$this->db->from($this->dbname);
		//加载分页类
		$this->load->library('pagination');
		$config['base_url'] = site_url('admin/<?=$dbname;?>c/lst');
		/*不清楚where条件*/
		$count=$this->db->count_all_results('',false);
		$config['total_rows'] = $count;
		$config['per_page'] = $pSize;
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$config['first_link'] = '第一页';
		$config['last_link'] = '最后一页';
		//搜索保留条件
		$config['reuse_query_string']=true;
		$this->pagination->initialize($config);
		/*翻页字符串*/
		$pageString=$this->pagination->create_links();
		/*分页获取*/
		/*偏移量*/
		$offset=($this->pagination->cur_page-1)*$pSize;
		$offset=$offset>0?$offset:0;
		$this->db->order_by('id','desc');
		$data=$this->db->get('',$pSize,$offset);
		/*返回数据*/
		return array('page'=>$pageString,'data'=>$data);
	}
	public function _before_delete($id){
		//删除之前要做的事情
	}
	public function _before_insert(&$data){
		//插入之前要做的事情
	}
	public function _after_insert($data){
		//插入之后要做的事情
	}
	public function _before_update(&$data){
		//更新之前要做的事情
	}
	public function _after_update($data){
		//更新之后要做的事情
	}
}
